﻿@using QqhrCitizen.Models.ViewModel;
@using QqhrCitizen.Models;
@model  QqhrCitizen.Models.ViewModel.vUserEdit
@{
    User user = ViewBag.User as User;
    ViewBag.Title = "修改用户信息修改 - 齐齐哈尔市民学习网";
}

<script src="~/Scripts/jquery.datetimepicker.js"></script>
<div id="d_menu" class="d-menu menu-use">
    <div id="d_menu_c" class="d-menu-c">
        <!-- region start: menu -->
        <div id="d_headmenu" class="d-headmenu">
            <div class="body">
                <a id="headmenu_useraccount" class="item_selected" href="/User/Show/@user.ID">个人信息</a>
                <a id="headmenu_history" class="item" href="/User/HistoryCourse/@user.ID">学习档案</a>
            </div>
        </div>
        <!-- region end: menu -->
    </div>
</div>
<script>

    function UserEditCheck() {
        if (!CheckPhone()) return false;
        if (!CheckEmail()) return false;
        if (!CheckBirthday()) return false;
    }

    function CheckPhone() {
        if ($("#Phone").val() != "") {
            if ($("#Phone").val().length > 14 || $("#Phone").val().length < 6) {
                CastMsg("电话格式不正确");
                return false;
            }
        }
        return true;
    }
    function CheckEmail() {
        if ($("#Email").val() != "") {
            var myreg = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
            if (!myreg.test($("#Email").val())) {
                CastMsg("邮箱格式输入错误！");
                return false;
            }
        }
        return true;
    }
    function CheckBirthday() {

        if ($("#Birthday").val() != "") {

            var str = $("#Birthday").val()
            var year = Convert.ToInt32(str.Substring(0, 3));
            var month = Convert.ToInt32(str.Substring(5, 2));
            var bzh = "";
            if (year / 4 == 0) {
                if (!Regex.IsMatch(str, "^[1-2][0-9][0-9][0-9][-](([0][2]))[-](([2][9])|([3][0-1]))$")) {
                    bzh = "(^[1-2][0-9][0-9][0-9][-](([0][1,3,5,7,8])|([1][0,2]))[-](([0][0-9])|([1-2][0-9])|([3][0-1]))$)|(^[1-2][0-9][0-9][0-9][-](([0][4,6,9])|([1][1]))[-](([0][0-9])|([1-2][0-9])|([3][0]))$)";
                }
                else
                    CastMsg("生日输入错误");
                return false;
                if (Regex.IsMatch(str, bzh)) {
                    return true;
                }
                else
                    CastMsg("生日输入错误");
                return false;
            }
            if (year / 4 != 0) {
                if (!Regex.IsMatch(str, "^[1-2][0-9][0-9][0-9][-](([0][2]))[-]([3][0-1])$")) {
                    bzh = "(^[1-2][0-9][0-9][0-9][-](([0][1,3,5,7,8])|([1][0,2]))[-](([0][0-9])|([1-2][0-9])|([3][0-1]))$)|(^[1-2][0-9][0-9][0-9][-](([0][4,6,9])|([1][1]))[-](([0][0-9])|([1-2][0-9])|([3][0]))$)";
                }
                else
                    CastMsg("生日输入错误");
                return false;
                if (Regex.IsMatch(str, bzh)) {
                    return true;
                }
                else
                    CastMsg("生日输入错误");
                return false;
            }
        }
    }

    $(function () {
        $('.datetime').datetimepicker();
    });
</script>
<div id="d_bottom" class="d-bottom" style="visibility: hidden; position: fixed;"><div class="d-bottom-c"><div id="d_scrolltop" class="d-scrolltop" style="right: -70px;"><span class="t" onclick="$('html,body').animate({scrollTop: '0px'}, 800);">顶部</span></div></div></div>
<div class="d-row" style="padding:0 0 40px 0">
    <div class="d-row-c">
        <div class="d-col-2-8">
            <div class="contentarea">
                @using (Html.BeginForm("Edit", "User", FormMethod.Post, new
                {
                    onsubmit = "return UserEditCheck();",
                    enctype = "multipart/form-data"
                }))
                {
                    @Html.AntiForgerySID()
                    @Html.HiddenFor(model => model.ID, new { @value = user.ID })
                    <div id="d_personalinfo" class="d-personalinfo">
                        <div class="head">
                            修改个人信息
                        </div><table class="tbl">
                            <tr>
                                <td style="width:100px;">
                                    <div>
                                        用户名
                                    </div>
                                </td>
                                <td>
                                    <div>
                                        @user.Username
                                        @Html.HiddenFor(modal => modal.Username, new { @Value = user.Username })
                                    </div>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    <div>
                                        <label for="Realname">真实姓名</label>
                                    </div>
                                </td>
                                <td>
                                    <div>
                                        @Html.TextBoxFor(model => model.Realname, new { @Value = user.Realname, @class = "int-hs nullable", @style = "width:150px" })<br />
                                        <span class="text">仅用于显示，不用于用户登录。长度为20个字符，一个汉字为2个字符。</span>
                                    </div>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    <div>
                                        <label for="Sex">性别</label>
                                    </div>
                                </td>
                                <td>
                                    <div>
                                        @Html.DropDownListFor(model => model.Sex, ViewBag.Sex as IEnumerable<SelectListItem>, new { @class = "int-hs nullable", @style = "width:150px" })
                                    </div>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    <div>
                                        <label for="Age">年龄</label>
                                    </div>
                                </td>
                                <td>
                                    <div>
                                        @Html.TextBoxFor(model => model.Age, new { @Value = user.Age, @class = "int-hs nullable", @style = "width:150px" })<br>
                                        <span class="text"></span>
                                    </div>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    <div>
                                        <label for="Email">电子邮箱</label>
                                    </div>
                                </td>
                                <td>
                                    <div>
                                        @Html.TextBoxFor(model => model.Email, new { @Value = user.Email, @class = "int-hs nullable", @style = "width:150px" })<br />
                                        <span class="text"></span>
                                    </div>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    <div>
                                        <label for="Birthday">生日</label>
                                    </div>
                                </td>
                                <td>
                                    <div>
                                        @Html.TextBoxFor(model => model.Birthday, new { @Value = user.Birthday, @class = "w-3 datetime nullable" })<br />
                                        <span class="text"></span>
                                    </div>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    <div>
                                        <label for="Phone">电话</label>
                                    </div>
                                </td>
                                <td>
                                    <div>
                                        @Html.TextBoxFor(model => model.Phone, new { @class = "int-hs nullable", @style = "width:150px ", @Value = @user.Phone })<br />
                                        <span class="text"></span>
                                    </div>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    <div>
                                        <label for="Address">地址</label>
                                    </div>
                                </td>
                                <td>
                                    <div>
                                        @Html.TextBoxFor(model => model.Address, new { @Value = @user.Address, @class = "int-hs nullable", @style = "width:200px" })<br />
                                        <span class="text"></span>
                                    </div>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    <div>
                                        头像（不修改请，留空）
                                    </div>
                                </td>
                                <td>
                                    <div id="avatarContainer">
                                        @if (user.Picture == null)
                                        {
                                            <img src="/Images/userphoto.png" width="100" height="100" style="border-radius:50%;" id="avatar" />
                                        }
                                        else
                                        {
                                            <img src="/User/ShowPicture/@user.ID" width="100" height="100" style="border-radius:50%;" alt="图像" id="avatar" />
                                        }
                                        <input value="/User/ShowPicture/@user.ID" id="Pic" name="Pic" type="hidden">
                                        <div>
                                            <span class="btn btn-orange fileinput-button">
                                                <span style="font-size:13px;">本地上传</span>
                                                <input id="fileupload" type="file" class="nullable" name="file">
                                            </span>
                                        </div>
                                    </div>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    <div>

                                    </div>
                                </td>
                                <td>
                                    <div>
                                        <input type="submit" class="btn btn-orange btn-big" value="保存" style="width:300px;">
                                    </div>
                                </td>
                            </tr>
                        </table>
                        <div class="info">
                            我们保证以上信息仅用于齐齐哈尔市民学习网用户实名身份认证，不会用于其他商业用途。
                        </div>
                    </div><!-- region end: 个人信息 -->
                }
            </div>
        </div><div class="d-col-2-4">
            <div class="contentarea">
                <!-- region start: 个人设置 -->
                <div id="d_settings" class="d-settings">
                    <div class="head">
                        &nbsp;
                    </div><div class="body">
                        <div class="item">
                            <a href="/User/PwdEdit/@user.ID">修改密码</a>
                        </div>
                        <div class="item">
                            <a href="/User/Edit/@user.ID">修改个人信息</a>
                        </div>
                        <!--<div class="item">
                            <a href="/usercenter/verify">实名认证</a>
                        </div>-->
                    </div>
                </div>
                <!-- region end: 个人设置 -->
                <input type="hidden" id="redirect" name="redirect">
            </div>
        </div>
        <div class="clear"></div>
    </div>
</div>
